import os, re, time

if os.path.isfile("o1000k.ap"):
    a = time.clock()
    data = open("o1000k.ap").read()
    links = re.findall('GET .* HTTP|EAD .* HTTP|OST .* HTTP', data)
    data = "\n" + data
    ips = re.findall('\n.* - -', data)
    def mask(x,y): return [str(x)[4:-5],str(y)[1:-4]]
    ip = map(mask, links, ips)
    ip.sort()
 
    j = 0
    num2 = 0
    dict = [[ip[0][0],0,ip[0][1],0]]
    for i in xrange(len(ip)):
        if ip[i][1]==dict[j][2]: num2=num2+1
        else:
            dict[j][3] = num2
            j=j+1
            dict.append([ip[i][0],0,ip[i][1],0])
            num2 = 1
    dict[j][3]=num2

    j = 0
    num = 0
    dictionary = [[dict[0][0],0,dict[0][2],dict[0][3]]]
    for i in xrange(len(dict)):
        if dict[i][0]==dictionary[j][0]:
            num=num+dict[i][3]
            if (dict[i][3]>dictionary[j][3]):
                dictionary[j][3]=dict[i][3]
        else:
            dictionary[j][1] = num
            j=j+1
            dictionary.append([dict[i][0],0,dict[i][2],dict[i][3]])
            num = dict[i][3]
    dictionary[j][1]=num

    file = open("log.txt", "w")
    for i in xrange(len(dictionary)):
        file.write(dictionary[i][0]+" - "+str(dictionary[i][1])+" - "+dictionary[i][2]+"\r\n")
    a1 = time.clock() - a
    file.write("Time of calculation: "+str(a1))
    file.close()